package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/menu")
public class MenuController {

    @DubboReference
    private MenuService menuService;

    /**
     * 根据用户名展示菜单列表
     * @param username
     * @return
     */
    @GetMapping("/getMenuList")
    public Result getMenuList(@RequestParam String username) {
        try {
            List<Menu> lists=menuService.getMenuList(username);
            return new Result(true, MessageConst.GET_MENU_SUCCESS, lists);
        } catch (Exception e) {
            log.error("",e);
            return new Result(false,MessageConst.GET_MENU_FAIL);
        }
    }
}
